package cn.zwk.excel;

import java.util.Objects;

/**
 * 列选择器：支持按索引或按表头名称指定一列。
 * 约定：索引从0开始；headerName 区分大小写。
 */
public final class ColumnSelector {
    private final Integer index; // 0-based
    private final String headerName;

    private ColumnSelector(Integer index, String headerName) {
        this.index = index;
        this.headerName = headerName;
    }

    public static ColumnSelector byIndex(int index) {
        return new ColumnSelector(index, null);
    }

    public static ColumnSelector byHeader(String headerName) {
        return new ColumnSelector(null, Objects.requireNonNull(headerName, "headerName"));
    }

    public boolean isIndexBased() {
        return index != null;
    }

    public Integer index() {
        return index;
    }

    public String headerName() {
        return headerName;
    }

    @Override
    public String toString() {
        if (isIndexBased()) {
            return "ColumnSelector{index=" + index + '}';
        }
        return "ColumnSelector{header='" + headerName + "'}";
    }
}

